﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Deployment;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.IO;
using System.Collections;
using System.Windows.Forms.DataVisualization.Charting;

namespace Workshop
{
    public partial class FormInstructorInfoChart : Form
    {
        public FormInstructorInfoChart()
        {
            InitializeComponent();
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void courseTimeToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void chart1_Click(object sender, EventArgs e)
        {

        }

        private void FormInstructorInfoChart_Load(object sender, EventArgs e)
        {
            CreateInstructor();
        }

        private void CreateInstructor()
        {
            //if the file exist, we will add the course into the xml
            if (File.Exists("Staff.xml"))
            {

                XmlDocument doc = new XmlDocument();
                doc.Load("Staff.xml");   //read the xml
                XmlNode node1 = doc.SelectSingleNode("//Staffs/Instructors");

                //a array to save data
                ArrayList WorkloadArray = new ArrayList();
                ArrayList NameArray = new ArrayList();
                for (int i = 0; i < node1.ChildNodes.Count; i++)
                {
                    XmlNode c = node1.ChildNodes[i];
                    WorkloadArray.Add(double.Parse(c.Attributes["Workload"].Value));
                    NameArray.Add(c.Attributes["Name"].Value);
                }


                //Title
                cht1.Titles.Add("Workload of instructors");
                cht1.Titles[0].ForeColor = Color.Black;
                cht1.Titles[0].Font = new Font("Arial", 20f, FontStyle.Regular);
                cht1.Titles[0].Alignment = ContentAlignment.TopCenter;


                //contrl the background
                cht1.BackColor = Color.White;

                //background in the chart area
                cht1.ChartAreas[0].BackColor = Color.Transparent;
                cht1.ChartAreas[0].BorderColor = Color.Transparent;

                //the label on X axis
                cht1.ChartAreas[0].AxisX.Interval = 1;
                cht1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
                cht1.ChartAreas[0].AxisX.LabelStyle.Angle = -50;
                cht1.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 14f, FontStyle.Regular);
                cht1.ChartAreas[0].AxisX.TitleForeColor = Color.Black;

                //the color of X axis
                cht1.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a");
                cht1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black;
                cht1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Arial", 10f, FontStyle.Regular);

                //the title of X axis
                cht1.ChartAreas[0].AxisX.Title = "Instructor";
                cht1.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 10f, FontStyle.Regular);
                cht1.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
                cht1.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal;


                //Line of X axis
                cht1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
                cht1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Transparent;

                //the color of Y axis
                cht1.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
                cht1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black;
                cht1.ChartAreas[0].AxisY.LabelStyle.Font = new Font("Arial", 10f, FontStyle.Regular);

                //the title of Y axis
                cht1.ChartAreas[0].AxisY.Title = "Workload";
                cht1.ChartAreas[0].AxisY.TitleFont = new Font("Arial", 10f, FontStyle.Regular);
                cht1.ChartAreas[0].AxisY.TitleForeColor = Color.Black;


                //Line of Y axis
                cht1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
                cht1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Transparent;

                cht1.ChartAreas[0].AxisY2.LineColor = Color.Transparent;

                cht1.Series[0].Label = "#VAL";                //Show the value of X and Y    
                cht1.Series[0].LabelForeColor = Color.Black;
                cht1.Series[0].ToolTip = "#VALX:#VAL";     //show the value want your mouse move on it


                cht1.Series[0].Color = Color.Lime;
                cht1.Series[0].IsValueShownAsLabel = true;
                cht1.Series[0].LabelForeColor = Color.Black;
                cht1.Series[0].CustomProperties = "DrawingStyle = Cylinder";



                //Bind data together
                //int workload;
                cht1.Series[0].Points.DataBindXY(NameArray, WorkloadArray);
                for (int i = 0; i < cht1.Series[0].Points.Count; i++)
                {
                    //color
                    XmlNode a = node1.ChildNodes[i];
                    if (double.Parse(a.Attributes["Workload"].Value) < 3)
                    {
                        cht1.Series[0].Points[i].Color = ColorTranslator.FromHtml("#8DB6CD");//#8DB6CD
                    }
                    else
                    {
                        cht1.Series[0].Points[i].Color = ColorTranslator.FromHtml("#191970");  //#38587a
                    }

                }
            }
            else
            {
                MessageBox.Show("No data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void CreateTA()
        {

            //if the file exist, we will add the course into the xml
            if (File.Exists("Staff.xml"))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("Staff.xml");   //read the xml
                XmlNode node1 = doc.SelectSingleNode("//Staffs/HeadTAs");

                //a array to save data
                ArrayList WorkloadArray = new ArrayList();
                ArrayList NameArray = new ArrayList();
                for (int i = 0; i < node1.ChildNodes.Count; i++)
                {
                    XmlNode c = node1.ChildNodes[i];
                    WorkloadArray.Add(double.Parse(c.Attributes["Workload"].Value));
                    NameArray.Add(c.Attributes["Name"].Value);
                }



                //Title
                cht1.Titles.Add("Workload of TA");
                cht1.Titles[0].ForeColor = Color.Black;
                cht1.Titles[0].Font = new Font("Arial", 20f, FontStyle.Regular);
                cht1.Titles[0].Alignment = ContentAlignment.TopCenter;

                //contrl the background
                cht1.BackColor = Color.White;

                //the background in the chart area
                cht1.ChartAreas[0].BackColor = Color.Transparent;
                cht1.ChartAreas[0].BorderColor = Color.Transparent;

                //the label on X axis
                cht1.ChartAreas[0].AxisX.Interval = 1;
                cht1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
                cht1.ChartAreas[0].AxisX.LabelStyle.Angle = -30;
                cht1.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 14f, FontStyle.Regular);
                cht1.ChartAreas[0].AxisX.TitleForeColor = Color.Black;

                //the color of X axis
                cht1.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a");
                cht1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black;
                cht1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Arial", 10f, FontStyle.Regular);

                //the title of X axis
                cht1.ChartAreas[0].AxisX.Title = "Name of TA";
                cht1.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 10f, FontStyle.Regular);
                cht1.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
                cht1.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal;

                //Line of X axis
                cht1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
                cht1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Transparent;

                //the color of Y axis
                cht1.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
                cht1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black;
                cht1.ChartAreas[0].AxisY.LabelStyle.Font = new Font("Arial", 10f, FontStyle.Regular);

                //the title of Y axis
                cht1.ChartAreas[0].AxisY.Title = "Workload";
                cht1.ChartAreas[0].AxisY.TitleFont = new Font("Arial", 10f, FontStyle.Regular);
                cht1.ChartAreas[0].AxisY.TitleForeColor = Color.Black;


                //Line of Y axis
                cht1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
                cht1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Transparent;

                cht1.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
                cht1.ChartAreas[0].BackGradientStyle = GradientStyle.TopBottom;


                cht1.Series[0].Label = "#VAL";                //Show the value of X and Y    
                cht1.Series[0].LabelForeColor = Color.Black;
                cht1.Series[0].ToolTip = "#VALX:#VAL";     //show the value want your mouse move on it


                cht1.Series[0].Color = Color.Lime;
                cht1.Series[0].IsValueShownAsLabel = true;
                cht1.Series[0].LabelForeColor = Color.Black;
                cht1.Series[0].CustomProperties = "DrawingStyle = Cylinder";



                //Bind data together
                cht1.Series[0].Points.DataBindXY(NameArray, WorkloadArray);
                for (int i = 0; i < cht1.Series[0].Points.Count; i++)
                {
                    //color
                    XmlNode a = node1.ChildNodes[i];
                    if (double.Parse(a.Attributes["Workload"].Value) == 6)
                    {
                        cht1.Series[0].Points[i].Color = ColorTranslator.FromHtml("#DC143C");//#8DB6CD
                    }
                    else
                    {
                        cht1.Series[0].Points[i].Color = ColorTranslator.FromHtml("#ff9933");  //#38587a
                    }
                }
            }

            else
            {
                MessageBox.Show("Please input some data first!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        //this is the button to switch TA chart and Instructor chart
        private void button1_Click(object sender, EventArgs e)
        {
            string text = this.button1.Text;
            //change the text if the button was clicked
            this.button1.Text = text == "Instructor" ? "TA" : "Instructor";
            if (this.button1.Text == "Instructor")
            {
                cht1.Titles.Clear();    //clear the title
                CreateTA();     //call function to show TA chart
            }
            else
            {
                cht1.Titles.Clear();       //clear the title
                CreateInstructor();     //call function to show Instructor chart
            }
        }

        private void courseTimeToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            FormITgroups form1 = new FormITgroups();
            this.Hide();
            form1.Show();
        }

        private void courseInformationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormCourseinformation form1 = new FormCourseinformation();
            this.Hide();
            form1.Show();
        }

        private void tAArrangementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            this.Hide();
            form1.Show();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            FormHeadPixel headPixel = new FormHeadPixel();
            headPixel.Show();
            this.Close();
        }
    }
}
